package com.hospital.phyexam.impl;

import com.alibaba.fastjson.JSON;
import com.hospital.phyexam.dao.DepartmentMapper;
import com.hospital.phyexam.entity.Department;
import com.hospital.phyexam.service.DepartService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Service
public class DepartServiceImpl implements DepartService {

    @Autowired
    DepartmentMapper departmentMapper;

    @Override
    public String getAll() {
        List<Department> departments = departmentMapper.selectAll();
        List<Map<String, String>> resaultmap = new ArrayList<>();
        Map<String, String> deptMap;
        for (Department department : departments) {
            deptMap = new HashMap<>();
            deptMap.put("id", department.getId().toString());
            deptMap.put("departNum", department.getDepartNum());
            deptMap.put("departName", department.getDepartName());
            deptMap.put("departRemark", department.getDepartRemark());
            resaultmap.add(deptMap);
        }
        return JSON.toJSONString(departments);
    }

}
